﻿@inherits ProComponentBase
@inject GlobalConfig GlobalConfig;
@inject NavHelper NavHelper

<div class="ml-10">
    @foreach (var menu in GetFavoriteMenus())
    {
        <MTooltip Color="primary" Bottom>
            <ActivatorContent>
                <span @attributes="@context.Attrs" class="hover-pointer mr-8"  @onclick="()=>NavHelper.NavigateTo(menu)">
                    <MIcon Size=24 Color="@(NavHelper.CurrentUri.EndsWith(menu.Href) ?"primary":"neutral-lighten-3")">
                        @menu.ParentIcon
                    </MIcon>
                </span>
            </ActivatorContent>
            <ChildContent>
                <span>@GetI18nFullTitle(menu.FullTitle)</span>
            </ChildContent>
        </MTooltip>
    }
    <MMenu OffsetY Bottom Right CloseOnContentClick="false" ValueChanged="OnOpen" Value="_open" MinWidth="@("auto")">
        <ActivatorContent>
             <MTooltip Color="primary" Bottom>
                <ActivatorContent Context="tooltipContext">
                    @{
                        var attrs = new Dictionary<string, object>();
                        foreach (var (key,value) in context.Attrs)
                        {
                            attrs.Add(key,value);
                        }
                        foreach (var (key,value) in tooltipContext.Attrs)
                        {
                            if(attrs.ContainsKey(key) is false) attrs.Add(key,value);
                        }
                    }
                    <MIcon @attributes="@attrs" Size=20 Color="dark-yellow">mdi-star-outline</MIcon>
                </ActivatorContent>
                <ChildContent>
                    <span>@T("Favorite")</span>
                </ChildContent>
            </MTooltip>
        </ActivatorContent>
        <ChildContent>           
            <MList Class="pb-1" Style="min-width:320px;">
                    <MListItem Class="mb-1">
                        <MTextField @bind-Value="_search" Class="rounded-2" HideDetails="@("auto")" Flat Dense Solo BackgroundColor="fill-lighten-1" Placeholder="Search"></MTextField>     
                    </MListItem>
                    @foreach (var nav in GetNavs(_search))
                    {
                        <MListItem Dense OnClick="()=> NavHelper.NavigateTo(nav)" Class="px-4">
                            <MListItemAction Class="mr-3">
                                <MIcon Size=20 Color="neutral-lighten-3">@nav.ParentIcon</MIcon>
                            </MListItemAction>
                            <MListItemContent>
                                <span Class="text-btn">@GetI18nFullTitle(nav.FullTitle)</span>
                            </MListItemContent>
                            <MListItemIcon Class="my-1">
                                <MButton Icon Text Color="dark-yellow" StopPropagation OnClick="()=>AddOrRemoveFavoriteMenu(nav.Id)">
                                    <MIcon Size=20>@(_favoriteMenus.Contains(nav.Id)?" mdi-star":"mdi-star-outline")</MIcon>
                                </MButton>
                            </MListItemIcon>
                        </MListItem>
                    }
                </MList>
        </ChildContent>
    </MMenu>
</div>
